#include <bits/stdc++.h>
using namespace std;

struct node
{
    char v;
    int cnt;
    unordered_map<char, node *> next;
    node(char a) : v(a), cnt(0) {}
};

int n, m;
bool ok[10001];
string p;

int main()
{
    node *tree = new node(' ');
    string s;
    cin >> n >> m;

    // 构建字典树
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        node *q = tree;
        for (char c : s)
        {
            if (!q->next[c])
            {
                q->next[c] = new node(c);
            }
            q = q->next[c];
        }
        q->cnt = i + 1;
    }

    // 处理每个查询
    for (int i = 0; i < m; i++)
    {
        cin >> p;
        memset(ok, 0, sizeof(ok));
        queue<tuple<node *, int, int>> qaq;
        qaq.push(make_tuple(tree, 0, 0));
        int ans = 0, flag = false;
        while (!qaq.empty())
        {
            int SIZE = qaq.size();
            for (int k = 0; k < SIZE; k++)
            {
                auto [current, index, modified] = qaq.front();
                qaq.pop();
                if (current == nullptr)
                    continue;
                if (modified == 0 && current->cnt > 0 && index == p.size())
                {
                    flag = true;
                    break;
                }
                if (index == p.size() && !ok[current->cnt] && current->cnt > 0){
                    ok[current->cnt] = true;
                    ans++;
                    continue;
                }
                // 正常匹配
                if (current->next[p[index]])
                    qaq.push(make_tuple(current->next[p[index]], index + 1, modified));
                if (modified == 0 && modified == 0)
                {
                    qaq.push(make_tuple(current, index + 1, 1));
                    for (auto &[ch, nextNode] : current->next)
                        if (ch != p[index])
                            qaq.push(make_tuple(nextNode, index + 1, 1));
                    for (auto &[ch, nextNode] : current->next)
                        qaq.push(make_tuple(nextNode, index, 1));
                }
                
            }
        }
        cout << (!flag ? ans : -1) << endl;
    }

    return 0;
}